package com.eras.shoes.ui

import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.TextView
import androidx.activity.ComponentActivity
import com.eras.shoes.R
import com.eras.shoes.utils.ToastUtils
import com.google.zxing.integration.android.IntentIntegrator
import com.google.zxing.integration.android.IntentResult

class InsoleOneActivity : ComponentActivity(), View.OnClickListener {

    private val btnBack: TextView by lazy { findViewById<TextView>(R.id.tv_insole_back_one) }
    private val btnScanCodeOne: Button by lazy { findViewById<Button>(R.id.btn_scan_code_one) }
    private val tvSerialNumberOne: TextView by lazy { findViewById<TextView>(R.id.tv_serial_number_one) }
    private val tvSerialNumberComparisonResultOne: TextView by lazy { findViewById<TextView>(R.id.tv_serial_number_comparison_result_one) }
    private val btnPutinComparisonOne: Button by lazy { findViewById<Button>(R.id.btn_putin_comparison_one) }
    private val tvPutinComparisonResultOne: TextView by lazy { findViewById<TextView>(R.id.tv_putin_comparison_result_one) }
    private val btnSaveOne: Button by lazy { findViewById<Button>(R.id.btn_save_one) }
    private val tvSaveResultOne: TextView by lazy { findViewById<TextView>(R.id.tv_save_result_one) }
//    private val btnScanCodeTwo: Button by lazy { findViewById<Button>(R.id.btn_scan_code_two) }
//    private val tvSerialNumberTwo: TextView by lazy { findViewById<TextView>(R.id.tv_serial_number_two) }
//    private val tvSerialNumberComparisonResultTwo: TextView by lazy { findViewById<TextView>(R.id.tv_serial_number_comparison_result_two) }
//    private val btnPutinComparisonTwo: Button by lazy { findViewById<Button>(R.id.btn_putin_comparison_two) }
//    private val tvPutinComparisonResultTwo: TextView by lazy { findViewById<TextView>(R.id.tv_putin_comparison_result_two) }
//    private val btnSaveTwo: Button by lazy { findViewById<Button>(R.id.btn_save_two) }
//    private val tvSaveResultTwo: TextView by lazy { findViewById<TextView>(R.id.tv_save_result_two) }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.layout_insole_one)
        btnBack.setOnClickListener(this)
        btnScanCodeOne.setOnClickListener(this)
        btnPutinComparisonOne.setOnClickListener(this)
        btnSaveOne.setOnClickListener(this)
//        btnScanCodeTwo.setOnClickListener(this)
//        btnPutinComparisonTwo.setOnClickListener(this)
//        btnSaveTwo.setOnClickListener(this)

    }

    override fun onClick(p0: View?) {
        val toast = ToastUtils()
        when (p0?.id){
            R.id.tv_insole_back_one -> {
                finish()
            }
            R.id.btn_scan_code_one -> {
                // 扫描二维码
                IntentIntegrator(this).initiateScan()
            }
            R.id.btn_putin_comparison_one -> {
                toast.show(this, "鞋垫1入库比对")
            }
            R.id.btn_save_one -> {
                toast.show(this, "保存鞋垫1上传序列号")
            }
//            R.id.btn_scan_code_two -> {
//                // 扫描二维码
//                IntentIntegrator(this).initiateScan()
//            }
//            R.id.btn_putin_comparison_two -> {
//                toast.show(this, "鞋垫2入库比对")
//            }
//            R.id.btn_save_two -> {
//                toast.show(this, "保存鞋垫2上传序列号")
//            }

        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        val result: IntentResult? = IntentIntegrator.parseActivityResult(requestCode, resultCode, data)
        if (result != null) {
            if (result.contents != null) {
                // 扫描结果，result.contents是二维码内容
                val qrCodeContent = result.contents
                ToastUtils().show(this, "qrCodeContent="+qrCodeContent)

                // 这里可以添加HTTP请求获取数据的代码
                // 例如使用kotlinx.coroutines或者其他网络库发起请求
            } else {
                // 扫描失败
            }
        } else {
            super.onActivityResult(requestCode, resultCode, data)
        }
    }

}